﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YFINGenerator
{
    public partial class Factory
    {
        public static string IServiceGenerator(EntityInfo entityInfo)
        {
            string v = entityInfo.Name.Remove(0, 5);
            v = v.Insert(1, v[0].ToString().ToLower());
            v = v.Remove(0, 1);
            string vk = entityInfo.Key;
            vk = vk.Insert(1, vk[0].ToString().ToLower());
            vk = vk.Remove(0, 1);
            string res = @"//
//此代码由YFINGenerator自动生成
//Copyright (c) 段凯强 2013~2014
//" + DateTime.Now +
                         @"
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using YFIN.Data;
using YFIN.Models;

namespace YFIN.Service." +
                         entityInfo.Directory + @"
{
    [ServiceContract]
    public interface I" +
                         entityInfo.Name.Remove(0, 5) +
                         @"Service
    {
        /// <summary>
        /// 添加一个" + entityInfo.Remark +
                         @"
        /// </summary>
        /// <param name=" +
                         "\"" + v + "\">要添加的" + entityInfo.Remark +
                         @"</param>
        [OperationContract]
        bool Add(" +
                         entityInfo.Name.Replace("YFIN_", "Model") + @" " + v +
                         @");

        /// <summary>
        /// 通过" +
                         vk + @"查找" + entityInfo.Remark + @"
        /// </summary>
        /// <param name=" + "\"" +
                         vk +
                         "\">" + vk + @"</param>
        /// <returns>找到的" + entityInfo.Remark +
                         @"</returns>
        [OperationContract]
        " +
                         entityInfo.Name.Replace("YFIN_", "Model") +
                         @" GetBy" + entityInfo.Key + @"(" + entityInfo.KeyType + @" " + vk +
                         @");";

            foreach(var e in entityInfo.ForeighKey)
            {
                string vfk = e.Substring(0,e.IndexOf(':'));
                vfk = vfk.Insert(1, vfk[0].ToString().ToLower());
                vfk = vfk.Remove(0, 1);
                res += @"

        /// <summary>
        /// 根据" + e.Substring(0, e.IndexOf(':')) + "查找所有" + entityInfo.Remark +
                       @"
        /// </summary>
        /// <param name=" + "\"" +
                       vfk +
                       "\">" + e.Substring(0, e.IndexOf(':')) + @"</param>
        /// <returns>找到的" + entityInfo.Remark +
                       @"</returns>
        [OperationContract]
        List<" +
                       entityInfo.Name.Replace("YFIN_", "Model") + "> GetBy" + e.Substring(0, e.IndexOf(':'))
                       + "(" + e.Substring(e.IndexOf(':') + 1) + " " + vfk + ");";
            }

            res += @"

        /// <summary>
        /// 更新" + entityInfo.Remark +
                   @"信息
        /// </summary>
        /// <param name=" + "\"new" + entityInfo.Name.Remove(0, 5) +
                   "\">更新后的" + entityInfo.Remark +
                   @"</param>
        /// <returns>是否成功</returns>
        [OperationContract]
        bool Update(" +
                   entityInfo.Name.Replace("YFIN_", "Model") + @" new" + entityInfo.Name.Remove(0, 5) +
                   @");

        /// <summary>
        /// 删除" + entityInfo.Remark +
                   @"
        /// </summary>
        /// <param name=" + "\"" + v + "\">要删除的" + entityInfo.Remark +
                   @"</param>
        /// <returns>是否成功</returns>
        [OperationContract]
        bool Delete(" +
                   entityInfo.Name.Replace("YFIN_", "Model") + @" " + v + @");
    }
}";
            return res;
        }
    }
}
